package com.a_baseTest;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

/**
 * Created by WDJ on 2019/10/31.
 */
public class Test_lambad01 {
        public static void main(String[] args) {
                new Thread(new Runnable(){
                        @Override
                        public void run() {
                                System.out.println("111");
                        }
                }).start();
                //lambad
                Runnable r2 = () -> System.out.println("hello lambda");
                r2.run();
                System.out.println("222");
        }

        /**
         * 接口就一个run方法，默认就是实现这个方法
         */
        @Test
        public void 测试lambad(){
                Runnable r2 = () -> System.out.println("hello lambda");
                r2.run();
        }

        /**
         * 有两个以上的参数，有返回值，并且Lambda体中有多条语句
         */
        @Test
        public void 测试lambad2(){
                Comparator<Integer> c1 = (x, y) -> {
                        System.out.print(Integer.compare(x, y)+"函数式接口");
                        return Integer.compare(x, y);
                };
//                c1.compare(1, 2);
        }

        @Test
        public void testList1(){
//                String str1 = "342";
//                List<String> strList = new ArrayList<>();
//                strList.add(str1);
//                strList.add(str1);
//                System.out.println(strList);

            User1 user1 = new User1();
            List<User1> userList = new ArrayList<>();
            userList.add(user1);
            userList.add(user1);
            System.out.println(userList);


        }


}

class User1 {
   private String sex;
   private int age;

   public User1() {}

        public String getSex() {
                return sex;
        }

        public void setSex(String sex) {
                this.sex = sex;
        }

        public int getAge() {
                return age;
        }

        public void setAge(int age) {
                this.age = age;
        }
}
